package com.tao.test;

import com.mysql.cj.jdbc.DatabaseMetaData;
import com.mysql.cj.util.StringUtils;
import com.tao.dao.UserMapper;
import com.tao.domain.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.IOException;
import java.io.Reader;
import java.util.List;

/**
 * @ClassName Demo
 * @Author HETAO
 * @Date 2020/7/25 21:36
 */
public class Demo {
    private static SqlSessionFactory sqlSessionFactory;

    @Before
    public void start(){
        try {
            Reader reader = Resources.getResourceAsReader("mybatis-config.xml");
            sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    @Test
    public void updateTestPlugin() {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        User user = new User();
        user.setUserName("321");
        mapper.update(1,user);
        sqlSession.commit(true);
    }
    @Test
    public void test () {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        List<User> user = mapper.findAll();
        sqlSession.close();
        SqlSession sqlSession3 = sqlSessionFactory.openSession();
        UserMapper mapper3 = sqlSession3.getMapper(UserMapper.class);
        List<User> user2 = mapper3.findAll();
        user2.forEach(System.out::println);
        sqlSession3.close();
        SqlSession sqlSession2 = sqlSessionFactory.openSession();
        UserMapper mapper2 = sqlSession2.getMapper(UserMapper.class);
        List<User> user3 = mapper2.findAll();
        user3.forEach(System.out::println);
    }

    @Test
    public void test2() {
        String str = "20256404,20258604,20263404,20258204,20255804,20261004,20262604,20000570,20259204,20261404," +
                "20000571,20259404,20257804,20255204,20257404,20257604,20262804,20256004,20257004,20263204,20259004,20259604,20260804,20259804,20257204,20256204,20000574,20260604,20255404,20263804,20262004,20262204,20256804,20264004,20263604,20261604,20258804,20260004,20260204,20256604,20261204,20258404,20261804,20262404,20255604,20000577,20252604,20260404";
        String[] split = str.split(",");
        System.out.println(split.length);

        String ss = "RES_WO_DEPOSIT,RES_W_DEPOSIT,TRANSFER_DEPOSIT,ALLOC_WO_DEPOSIT,ALLOC_W_DEPOSIT," +
                "CANCEL_WO_DEPOSIT,CANCEL_W_DEPOSIT,COLLECT_EXP_WO_DEPOSIT,COLLECT_EXP_W_DEPOSIT,DELIV,HANDLE_BY_CORP,INELIGIBLE,NEW_SUBSCRIBER,PEND_COLLECT_WO_DEPOSIT,PEND_COLLECT_W_DEPOSIT,PEND_REG,PRE_REG,REFUND,REQ_WO_DEPOSIT,REQ_W_DEPOSIT,RES_EXP_WO_DEPOSIT,RES_EXP_W_DEPOSIT";
        String[] status = ss.split(",");
        System.out.println(status.length);
    }
}
